import 'package:casdon/common/utils/string_externtion.dart';
import 'package:casdon/modules/recipe/data/api/miffy_recipe_cloud_list_api.dart';
import 'package:casdon/modules/recipe/ui/widgets/Recipe_card_item.dart';

class MiffyRecipeCloudModel extends RecipeCardData {
  @override
  int get sort => 0;
  final String id;
  final String name;
  final bool isControl;
  final String mainImg;
  final int browseNum;
  final bool isCollect;
  final int collectionNum;

  MiffyRecipeCloudModel({
    required this.id,
    required this.name,
    required this.isControl,
    required this.mainImg,
    required this.browseNum,
    required this.isCollect,
    required this.collectionNum,
  });
  @override
  String? get url => null;
  @override
  bool get isSmart => isControl;

  @override
  String get recipeId => id;

  @override
  String get imgUrl => mainImg.cropParams700;

  @override
  String get viewCount => '$browseNum';

  @override
  String get title => name;

  @override
  String get count => "0";

  @override
  RecipeCardData placeholder() {
    throw UnimplementedError();
  }

  // 静态方法转换
  static MiffyRecipeCloudModel fromApi(MiffyRecipeCloud response) {
    return MiffyRecipeCloudModel(
      mainImg: response.mainImg ?? "",
      name: response.name,
      isControl: (response.isControl == 1) ? true : false,
      browseNum: response.browseNum ?? 0,
      id: response.id,
      collectionNum: response.collectionNum ?? 0,
      isCollect: response.isCollect ?? false,
    );
  }

  // 批量转换的静态方法
  static List<MiffyRecipeCloudModel> listFromApi(List<MiffyRecipeCloud> items) {
    return items.map(fromApi).toList();
  }
}
